import { Component, OnInit } from '@angular/core';
import {filter} from "rxjs/operators";

declare var form: any;
declare var base: any;
@Component({
  templateUrl: './show.component.html'
})
export class ShowComponent implements OnInit {

  // 表单
  is: any;
  ds: any;
  fs: any;
  ps: any;
  // 字典
  zd_airport: any = null;
  selectDate: any;
  quertData: any = {};
  selectData: any = null;

  constructor() {


    this.zd_airport = new form.DictionaryService('zd_airport');
    this.zd_airport.loadAll();
  }

  ngOnInit() {
    this.initData();



  }

  initData() {

    this.selectDate = this.dateFormat('YYYY-mm-dd', new Date());
    this.quertData.createTime = this.selectDate;
    const url = base.BaseService.getHostUrl() + '/temporaryshow/getShowData';
    base.BaseService.post(url, this.quertData, (datas) => {
      this.selectData = datas;
    });
  }


  // 重写编辑方法，做编辑跳转，新增则传false即可
  editRow(item) {
    if (item) {
      window.open('#data_temporary_show_info_mis?info=true&id=' + item.id + '&date=' + this.selectDate);
    } else {
      window.open('#data_temporary_show_info_mis?info=true');
    }
  }

  dateFormat(fmt, date) {
    let ret;
    const opt = {
      'Y+': date.getFullYear().toString(),        // 年n
      'm+': (date.getMonth() + 1).toString(),     // 月
      'd+': date.getDate().toString(),            // 日
      'H+': date.getHours().toString(),           // 时
      'M+': date.getMinutes().toString(),         // 分
      'S+': date.getSeconds().toString()          // 秒
      // 有其他格式化字符需求可以继续添加，必须转化成字符串
    };
    for (const k in opt) {
      ret = new RegExp('(' + k + ')').exec(fmt);
      if (ret) {
        fmt = fmt.replace(ret[1], (ret[1].length === 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, '0')));
      }
    }
    return fmt;
  }

  editDate($event: any) {
    this.selectDate = this.dateFormat('YYYY-mm-dd', $event);
    this.quertData.createTime = this.selectDate;
    const url = base.BaseService.getHostUrl() + '/temporaryshow/getShowData';
    base.BaseService.post(url, this.quertData, (datas) => {
      this.selectData = datas;
    });
  }

  editPort($event: any) {
    this.quertData.airport = $event;
    const url = base.BaseService.getHostUrl() + '/temporaryshow/getShowData';
    base.BaseService.post(url, this.quertData, (datas) => {
      this.selectData = datas;
    });
  }
}
